/**
 * @author: dn-jinmin/dn-jinmin
 * @doc:
 */

package middleware

import "github.com/gin-gonic/gin"

type Csrf struct{}

func NewCsrf() *Csrf {
	return &Csrf{}
}

func (m *Csrf) Handler(ctx *gin.Context) {
	ctx.Header("Access-Control-Allow-Origin", "*")
	ctx.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
	ctx.Header("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization")
	ctx.Header("Access-Control-Expose-Headers", "Content-Length")
	ctx.Header("Access-Control-Allow-Credentials", "true")

	if ctx.Request.Method == "OPTIONS" {
		ctx.AbortWithStatus(200)
		return
	}
}
